package com.pj.fragment.adapter;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.pj.fragment.R;
import com.pj.fragment.bean.WebListBean;

import java.util.List;

public class ListItemAdapter extends BaseAdapter {

    List<WebListBean> data;
    private ImageView listItemIcon;
    private TextView listItemContent;

    public ListItemAdapter(List<WebListBean> data) {
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        @SuppressLint("ViewHolder") View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item, null);
        initView(v);
        listItemIcon.setImageResource(data.get(i).getImage());
        listItemContent.setText(data.get(i).getName());
        return v;
    }

    private void initView(View v) {
        listItemIcon = (ImageView) v.findViewById(R.id.list_item_icon);
        listItemContent = (TextView) v.findViewById(R.id.list_item_content);
    }
}
